package com.project.service;

import com.project.dao.JobApplyMapper;
import com.project.entity.JobApply;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: TateBrown
 * @date: 2018/5/26 14:06
 * @param:
 * @return:
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class JobApplyServiceImpl extends BaseService implements JobApplyService {
    @Autowired
    private JobApplyMapper jobApplyMapper;

    /**
     * author: WheelChen
     * date: 2017/9/4
     * function: 添加一条应聘记录
     *
     * @param jobApply
     * @return
     */
    @Override
    public int addOne(JobApply jobApply) {
        return jobApplyMapper.insertSelective(jobApply);
    }

    /**
     * author: WheelChen
     * date: 2017/9/4
     * function: 根据id删除一条应聘记录
     *
     * @param id
     * @return
     */
    @Override
    public int removeOneById(Integer id) {
        return jobApplyMapper.deleteByPrimaryKey(id);
    }

    /**
     * author: WheelChen
     * date: 2017/9/4
     * function: 根据id修改一条应聘记录
     *
     * @param jobApply
     * @return
     */
    @Override
    public int modifyOneById(JobApply jobApply) {
        return jobApplyMapper.updateByPrimaryKeySelective(jobApply);
    }

    /**
     * author: WheelChen
     * date: 2017/9/5
     * function: 根据id查找应聘表
     *
     * @param id
     * @return
     */
    @Override
    public JobApply findOneById(Integer id) {
        return jobApplyMapper.selectByPrimaryKey(id);
    }

    /**
     * author: WheelChen
     * date: 2017/9/9
     * function: 根据应聘表模糊条件查找
     *
     * @param jobApply
     * @return
     */
    @Override
    public List<JobApply> findByCondition(JobApply jobApply) {
        return jobApplyMapper.selectByCondition(jobApply);
    }

    /**
     * author: WheelChen
     * date: 2017/9/19
     * function: 根据学生信息表idList批量删除
     *
     * @param studentInfoIdList
     * @return
     */
    @Override
    public int removeBatchByStudentInfoIdList(List studentInfoIdList) {
        return jobApplyMapper.deleteBatchByStudentInfoIdList(studentInfoIdList);
    }

    /**
     * author: WheelChen
     * date: 2017/11/22
     * function: 检查该条应聘记录是否已投递 根据stid（学生id）和recruitinfoid（招聘信息id）
     *
     * @param jobApply
     * @return
     */
    @Override
    public boolean checkIsDeliveredExist(JobApply jobApply) {
        return jobApplyMapper.checkIsDeliveredExist(jobApply) != 0;
    }
}
